package axonactive.vision.training.service;

import java.util.List;

import ch.ivyteam.ivy.environment.Ivy;

import axonactive.vision.training.dao.ExaminationDAO;
import axonactive.vision.training.dao.QuestionDAO;
import axonactive.vision.training.entity.Examination;
import axonactive.vision.training.entity.Question;

public class ExaminationService {
	private QuestionDAO questionDAO = new QuestionDAO();
	private ExaminationDAO examinationDAO = new ExaminationDAO();
	
	public List<Examination> getAllExam(){
		return examinationDAO.getAllExam();
	}
	
	public void removeExam(Examination exam){
		questionDAO.removeQuesByExamId(exam.getId());
		examinationDAO.removeExam(exam);
	}
	
	public void mergeExam(Examination exam, List<Question> listMergeQues, List<Question> listDeleteQues){
		Examination insertedExam = examinationDAO.mergeExam(exam);
		for(Question question : listMergeQues){
			question.setExamID(insertedExam.getId());
			questionDAO.mergeQues(question);
		}
		
		for(Question question : listDeleteQues){
			Ivy.log().info("flag delete begin");
			questionDAO.removeQues(question);
			Ivy.log().info("flag delete end");
		}
	}
}
